package com.cici.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cici.body.requestbody.TbTestStudentCreateRequestBody;
import com.cici.body.requestbody.TbTestStudentUpdateRequestBody;
import com.cici.entity.TbTestStudent;
import com.cici.exception.ExceptionEnumImpl;
import com.cici.exception.common.RestBadRequestException;
import com.cici.feign.accountservice.AccountServiceFeign;
import com.cici.mapper.TbTestStudentMapper;
import com.cici.service.ITbTestStudentService;
import com.cici.tools.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.List;





/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cici
 * @since 2018-11-30
 */
@Slf4j
@Service
public class TbTestStudentServiceImpl extends ServiceImpl<TbTestStudentMapper, TbTestStudent> implements ITbTestStudentService {

    @Autowired
    private TbTestStudentMapper tbTestStudentMapper;

    @Autowired
    private AccountServiceFeign accountServiceFeign;

     @Override
     public TbTestStudent create(TbTestStudentCreateRequestBody body){
            TbTestStudent tbTestStudent = new TbTestStudent();
            BeanUtils.copy(body,tbTestStudent);

            if (tbTestStudentMapper.insert(tbTestStudent)<1){
                throw new RestBadRequestException(ExceptionEnumImpl.CREATE_ERROR,"创建失败");
            }
            log.info("a" + tbTestStudent.toString());
//            log.info("输出：" +tbTestStudentMapper.selectById(body.getId()).getCity());
             return tbTestStudentMapper.selectById(tbTestStudent.getId());


     }

     @Override
     public  TbTestStudent update(Long id, TbTestStudentUpdateRequestBody body){


             return null;
     }

     @Override
     public List<TbTestStudent> selectTbTestStudentList(){
             return null;

     }

    @Override
    public TbTestStudent getTbTestStudent(long id) {
        TbTestStudent tbTestStudent = tbTestStudentMapper.selectById(id);
        tbTestStudent.setAddress(accountServiceFeign.getTbTestAddress().getAddress());
        return tbTestStudent;
    }

    @Override
     public boolean delete(Long id){

             return false;

     }

}
